package com.fessc.develop.job;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.fessc.develop.entity.comvo.BankCheckFileApplyVo;
import com.fessc.develop.entity.dbvo.TOrgUrlManage;
import com.fessc.develop.handler.BankCheckFileApplyPushHandler;
import com.fessc.develop.model.enums.EnumPushType;
import com.fessc.develop.model.enums.EnumTaskCode;
import com.fessc.develop.service.interfaces.ITCheckResultService;
import com.fessc.develop.service.interfaces.ITOrgUrlManageService;
import com.fessc.develop.utils.DateUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

@Slf4j
@Service
public class BankCheckFileApplyJob extends ScheduleJob {

    @Resource
    private BankCheckFileApplyPushHandler bankCheckFileApplyPushHandler;

    @Resource
    private ITCheckResultService checkResultService;

    @Override
    public String execute() {
        // 互联互通向银行发起对账文件申请，申请之后再调用接口下载对账文件
        log.info("对账文件申请");
        Date checkDate = null;
        try {
            checkDate = DateUtil.stringToDate(DateUtil.getLastDayDate(DateUtil.getCurrentDateTime(DateUtil.DATE_FORMAT), 1), DateUtil.DATE_FORMAT);
        } catch (Exception e) {
            log.info("获取前一天日期异常：" + e.getMessage());
        }
        // 查询对账申请银行编号
        List<BankCheckFileApplyVo> bankCheckApplyList = checkResultService.getBankCheckApplyListByDate(getCCBBankId(), checkDate);
        bankCheckFileApplyPushHandler.bankCheckFileApplyPush(bankCheckApplyList, EnumPushType.CHECKING_PUSH.toString());
        return null;
    }

    @Override
    public String getTaskCode() {
        return EnumTaskCode.BANK_CHECK_APPLY_PUSH.toString();
    }
}
